﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using UIT.ScrumTool.Client.Controller;
using UIT.ScrumTool.Client.ControlService;


namespace UIT.ScrumTool.Client.View.Project
{
    /// <summary>
    /// Interaction logic for dxwProjectList.xaml
    /// </summary>
    public partial class dxwProjectList : DXWindow
    {
        // List Project Cache 
        public static List<ProjectDto> lstProject = null;

        public dxwProjectList()
        {
            InitializeComponent();

            // Get Project List
            if (lstProject == null)
            {
                lstProject = ProjectCtrl.ProjectGetByAll().ToList();
            }

            this.listViewProject.ItemsSource = lstProject.OrderBy(item => item.Name);
            this.grdProjectList.ItemsSource = lstProject.OrderBy(item => item.Name);
        }

        private void lstView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItem selectItem = (ComboBoxItem) lstView.SelectedItem;
            if (lstView.SelectedIndex == 0)
            {
                // Grid view show
                this.grdProjectList.Visibility = System.Windows.Visibility.Visible;
                this.listViewProject.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                // Image show
                this.grdProjectList.Visibility = System.Windows.Visibility.Hidden;
                this.listViewProject.Visibility = System.Windows.Visibility.Visible;
            }
            
        }

        // Handle When Click Create New Project
        private void lbCreateProject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            uctrlProject._uctrlProject.lbCreateProject_MouseLeftButtonDown(sender, e);
            this.Close();
        }

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ProjectDto project = this.listViewProject.SelectedItem as ProjectDto;
            if (project != null)
            {
                this.Close();
                uctrlProject.projectId = project.Id;
                uctrlProject._uctrlProject.ShowProjectSelected(project);
                uctrlProject._uctrlProject.LoadListDocument(project.Id);
                uctrlProject._uctrlProject.LoadListMember(ProjectUserCtrl.GetProjectMember(project.Id));
            }
        }

        private void grdProjectList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ProjectDto project = this.grdProjectList.GetFocusedRow() as ProjectDto;
            if (project != null)
            {
                uctrlProject.projectId = project.Id;
                this.Close();
                uctrlProject._uctrlProject.ShowProjectSelected(project);
                uctrlProject._uctrlProject.LoadListDocument(project.Id);
                uctrlProject._uctrlProject.LoadListMember(ProjectUserCtrl.GetProjectMember(project.Id));
            }
        }
    }
}
